package PDFd.Layer;

/**
* <p>Title: Point</p>
* <p>Description:Represents an X and Y coord.  </p>
* @author Matt, Tom, Andrew, Kong
* @email matt.mckay@my.uwrf.edu,tom.florin@my.uwrf.edu,
* andrew.kathan@my.uwrf.edu,kong.xiong-1@my.uwrf.edu
* @date December 1st,2011*/
public class Point {
	public int x,y;
	public Point() {}
	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Find the distance (in the form of a Point) between this point and another point
	 * @param p
	 * @return
	 */
	public Point difference(Point p) {
		return new Point(p.x-this.x,p.y-this.y);
	}
	/**
	 * This method calculates the distance between
	 * points
	 * @param p
	 * @return Math.sqrt(Math.pow(this.x-p.x, 2) + Math.pow(this.y-p.y,2));
	 */
	public Double distance(Point p){
		return Math.sqrt(Math.pow(this.x-p.x, 2) + Math.pow(this.y-p.y,2));
	}
	
	/**
	 * This method calculates the difference between x, and y
	 * @param x
	 * @param y
	 * @return new Point(x-this.x, y-this.y);
	 */
	public Point difference(int x, int y){
		return new Point(x-this.x, y-this.y);
	}
	
	/**
	 * Scales our point
	 * @param scaleFactor
	 * @return p
	 */
	public Point scale(float scaleFactor) {
		Point p = new Point();
		p.x = (int) (this.x/scaleFactor);
		p.y = (int) (this.y/scaleFactor);
		return p;
	}

	/**
	 * Returns a boolean value comparing the points
	 * @param o
	 * @return
	 *  true: o points to the same object as this
	 *  true: o is a point and has the same x and y value as this
	 *  false: object is not a point or is null
	 */
	public boolean equals(Object o){
		if ((o != null && o == this) || (o instanceof Point && (((Point) o).x==this.x && ((Point) o).y ==this.y)))
			return true;
		return false;
	}
	/**
	 * Returns a toString
	 * @return toString
	 */
	public String toString() {
		return "X:"+x+" Y:"+y;
	}

	public int hashCode(){
		return this.toString().hashCode();
	}
	
}
